import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.annotation.WebInitParam;

import java.io.IOException;


@WebFilter(filterName = "charsetFilter",urlPatterns = "/*",initParams = @WebInitParam(name = "charset",value = "UTF-8"))
public class CharsetFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        FilterRegistration charsetFilter = servletRequest.getServletContext().getFilterRegistration("charsetFilter");

        String charset = charsetFilter.getInitParameter("charset");

        servletResponse.setContentType("text/html;charset="+charset);

        filterChain.doFilter(servletRequest,servletResponse);


    }
}
